package memento;

import memento.memento.ActorMemento;

//主角
public class Actor {
    String weapon;
    Integer live;
    Integer skills;
    Integer protect;

    Actor() {
        init();
       showDetail();
    }

    public void bigSkill() {
        if (this.skills < 3) {
            System.out.println("技能不足，请求队友支援！");
            return;
        }
        System.out.println("释放大招！");
        this.skills -= 3;
        showDetail();
    }

    public void smallSkill() {
        if (this.skills < 1) {
            System.out.println("技能不足，请求队友支援！");
            return;
        }
        System.out.println("释放攻击技能！");
        this.skills -= 1;
        showDetail();
    }

    public void beAttack(int value) {
        System.out.println("被攻击了");
        if (value > live) {
            System.out.println("阵亡！");
            return;

        }
        //减掉防护
        if (protect > 0) {
            this.protect -= value;
            if (protect < 0) {
                value = Math.abs(this.protect - value);
                this.live -= value;
            }
        } else {
            this.live -= value;
        }
        showDetail();
    }

    public void treatment() {
        System.out.println("队友治疗");
        this.live = Math.max(90, this.live);
        showDetail();
    }

    public void changeWeapon(String weapon) {
        System.out.println("切换武器");
        this.weapon = weapon;
        showDetail();
    }

    public void goHome() {
        System.out.println("回家了，回血成功");
        init();
        showDetail();
    }

    public ActorMemento saveProgress() {
        System.out.println("保存进度");
        return new ActorMemento(this.weapon, this.live, this.skills, this.protect);
    }

    public void recovery(ActorMemento memento) {
        System.out.println("恢复进度");
        this.weapon = memento.getWeapon();
        this.live = memento.getLive();
        this.skills = memento.getSkills();
        this.protect = memento.getProtect();
        showDetail();
    }

    private void init() {
        this.weapon = "尼泊尔";
        this.live = 100;
        this.skills = 5;
        this.protect = 10;
        System.out.println("初始化完毕");
    }

    public void showDetail(){
        System.out.println(this);
    }

    @Override
    public String toString() {
        return "Actor{" +
                "weapon='" + weapon + '\'' +
                ", live=" + live +
                ", skills=" + skills +
                ", protect=" + protect +
                '}';
    }
}
